package others 
{
	
	import mx.controls.ColorPicker;
	import mx.core.UIComponent;
	
	import spark.components.CheckBox;
	import spark.components.DropDownList;
	import spark.components.List;
	import spark.components.NumericStepper;
	import spark.components.TextInput;
	import spark.components.supportClasses.SliderBase;
	
	import view.components.CustomProperties;
	import view.components.HitAreaType;
	
	public class Util
	{
		
		public static function setCascadePropery(object:Object, property:String, value:Object) : void {
			var v:Array = property.split(".");
			var i:uint;
			for (i = 0; i < v.length - 1; i++){
				object = object[v[i]];
			}
			object[v[v.length - 1]] = value;
		}
		
		public static function getControlValue(control:UIComponent) : * {
			if (control is NumericStepper){
				return (control as NumericStepper).value;
			}else
				if (control is ColorPicker){
					return (control as ColorPicker).selectedColor;
				}else
					if (control is CheckBox){
						return (control as CheckBox).selected;
					}else
						if (control is DropDownList){
							return (control as DropDownList).selectedItem;
						}else
							if (control is SliderBase){
								return (control as SliderBase).value;
							}else
								if (control is CustomProperties){
									return (control as CustomProperties).value;
								}else
									if (control is List){
										return (control as List).selectedItem;
									}else
										if (control is HitAreaType){
											return (control as HitAreaType).value;
										}else
											if (control is TextInput){
												return (control as TextInput).text;
											}else{
												throw(new Error("Unable to get control value: Unknown control type!"));
											}
		}
		
		public static function getPropertyToControl(object:Object, control:UIComponent) : void {
			var v:Array = control.name.split(".");
			var i:uint;
			for (i = 0; i < v.length - 1; i++){
				object = object[v[i]];
			}
			
			if (control is NumericStepper){
				(control as NumericStepper).value = object[v[v.length - 1]];
			}else
				if (control is ColorPicker){
					(control as ColorPicker).selectedColor = object[v[v.length - 1]];
				}else
					if (control is CheckBox){
						(control as CheckBox).selected = object[v[v.length - 1]];
					}else
						if (control is DropDownList){
							(control as DropDownList).selectedItem = object[v[v.length - 1]];
						}else
							if (control is SliderBase){
								(control as SliderBase).value = object[v[v.length - 1]];
							}else
								if (control is CustomProperties){
									(control as CustomProperties).value = object[v[v.length - 1]];
								}else
									if (control is List){
										(control as List).selectedItem = object[v[v.length - 1]];
									}else
										if (control is HitAreaType){
											(control as HitAreaType).value = object[v[v.length - 1]];
										}else
											if (control is TextInput){
												(control as TextInput).text = object[v[v.length - 1]];
											}
		}
		
		
		
	}
}